package types

import (
	"encoding/hex"

	"gopkg.in/src-d/go-git.v4/plumbing"
)

// Hash from git
type Hash plumbing.Hash

func (h Hash) String() string {
	return plumbing.Hash(h).String()
}

// ZeroHash nil hash
var ZeroHash Hash

// Hiter Hit interface
type Hiter interface {
	Hit(Hash) bool
}

// SomeHiter some hiter
type SomeHiter []Hiter

// Hit interface
func (hs SomeHiter) Hit(hash Hash) bool {
	for _, h := range hs {
		if h.Hit(hash) {
			return true
		}
	}
	return false
}

// NewHash hash from string
func NewHash(hs string) Hash {
	h, err := hex.DecodeString(hs)
	if err != nil {
		return ZeroHash
	}
	var hash Hash
	copy(hash[:], h)
	return hash
}
